summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-01-04 00:06:07 -0700
committerMike Buland <eichlan@xagasoft.com>2012-01-04 00:06:07 -0700
commitd8f0276ec9d3b538a5ef8918a3072e3528a480d5 (patch)
tree41c8cb65f07053e6a0a4d15a0b0a5f5e1c56bb33
parent3a0f68b527cc85bd9847127085415739af784eca (diff)
downloadstage-d8f0276ec9d3b538a5ef8918a3072e3528a480d5.tar.gz
stage-d8f0276ec9d3b538a5ef8918a3072e3528a480d5.tar.bz2
stage-d8f0276ec9d3b538a5ef8918a3072e3528a480d5.tar.xz
stage-d8f0276ec9d3b538a5ef8918a3072e3528a480d5.zip
Parse moved to GameBuilder.
-rw-r--r--src/gamebuilder.cpp22
-rw-r--r--src/gamebuilder.h2
-rw-r--r--src/main.cpp23
3 files changed, 26 insertions, 21 deletions
diff --git a/src/gamebuilder.cpp b/src/gamebuilder.cpp
index 3cf2e1f..83cbe79 100644
--- a/src/gamebuilder.cpp
+++ b/src/gamebuilder.cpp
@@ -8,6 +8,7 @@
8#include "astfunction.h" 8#include "astfunction.h"
9#include "command.h" 9#include "command.h"
10#include "situation.h" 10#include "situation.h"
11#include "parser.tab.h"
11 12
12using namespace Bu; 13using namespace Bu;
13 14
@@ -27,6 +28,27 @@ GameBuilder::~GameBuilder()
27{ 28{
28} 29}
29 30
31typedef void *yyscan_t;
32void yylex_init( yyscan_t * );
33void yylex_destroy( yyscan_t );
34void yyparse( yyscan_t, GameBuilder &bld );
35void yyset_in( FILE *, yyscan_t );
36
37void GameBuilder::parse( const Bu::String &sFile )
38{
39 yyscan_t scanner;
40
41 yylex_init( &scanner );
42
43 FILE *in = fopen( sFile.getStr(), "rb" );
44 yyset_in( in, scanner );
45
46 yyparse( scanner, *this );
47 yylex_destroy( scanner );
48
49 fclose( in );
50}
51
30void GameBuilder::setLiteral( const Variable &v ) 52void GameBuilder::setLiteral( const Variable &v )
31{ 53{
32 vLiteral = v; 54 vLiteral = v;
diff --git a/src/gamebuilder.h b/src/gamebuilder.h
index b1e4d49..f3e3a1f 100644
--- a/src/gamebuilder.h
+++ b/src/gamebuilder.h
@@ -13,6 +13,8 @@ public:
13 GameBuilder(); 13 GameBuilder();
14 virtual ~GameBuilder(); 14 virtual ~GameBuilder();
15 15
16 void parse( const Bu::String &sFile );
17
16 class Game *getGame() { return pGame; } 18 class Game *getGame() { return pGame; }
17 19
18 void setLiteral( const Variable &v ); 20 void setLiteral( const Variable &v );
diff --git a/src/main.cpp b/src/main.cpp
index 5b91861..6646d79 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,7 +1,6 @@
1#include "gamebuilder.h" 1#include "gamebuilder.h"
2#include "game.h" 2#include "game.h"
3#include "gamestate.h" 3#include "gamestate.h"
4#include "parser.tab.h"
5 4
6#include <stdlib.h> 5#include <stdlib.h>
7#include <time.h> 6#include <time.h>
@@ -13,30 +12,12 @@
13#include <bu/sio.h> 12#include <bu/sio.h>
14using namespace Bu; 13using namespace Bu;
15 14
16typedef void *yyscan_t;
17void yylex_init( yyscan_t * );
18void yylex_destroy( yyscan_t );
19void yyparse( yyscan_t, GameBuilder &bld );
20void yyset_in( FILE *, yyscan_t );
21
22int main( int argc, char *argv[] ) 15int main( int argc, char *argv[] )
23{ 16{
24 yyscan_t scanner;
25
26 GameBuilder bld;
27
28 yylex_init( &scanner );
29
30 FILE *in = fopen( argv[1], "rb" );
31 yyset_in( in, scanner );
32
33 yyparse( scanner, bld );
34 yylex_destroy( scanner );
35
36 fclose( in );
37
38 srandom( time( NULL ) ); 17 srandom( time( NULL ) );
39 18
19 GameBuilder bld;
20 bld.parse( argv[1] );
40 Game *pGame = bld.getGame(); 21 Game *pGame = bld.getGame();
41 22
42 GameState gs( pGame ); 23 GameState gs( pGame );